package com.novax.ex.activity.provider.handler.consumer;

import com.novax.ex.activity.provider.service.InternalTransferOrderBigdataService;
import com.novax.ex.common.constant.MqConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;

/**
 * @Description
 * @Author zhaolei
 * @Date 10/24/24 5:08 PM
 * @Version 1.0
 */
@Component
@Slf4j
public class BeebInternalOrderConsumer {
    @Resource
    private InternalTransferOrderBigdataService internalTransferOrderBigdataService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConstants.Queue.BEEB_INTERNAL_ORDER, durable = "true"),
            exchange = @Exchange(value = MqConstants.Exchange.BEEB_INTERNAL_ORDER_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Exchange.BEEB_INTERNAL_ORDER_KEY)
    )
    public void exec(String message) {
        try {
            if (StringUtils.isNotBlank(message)){
                internalTransferOrderBigdataService.exec(message);
            }
        } catch (Exception e) {
            log.info(e.toString());
            log.info("消息队列丢失消息:" + message);
        }
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConstants.Queue.BEEB_INTERNAL_ORDER_HISTORY, durable = "true"),
            exchange = @Exchange(value = MqConstants.Exchange.BEEB_INTERNAL_ORDER_HISTORY_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Exchange.BEEB_INTERNAL_ORDER_HISTORY_KEY)
    )
    public void execHistory(String message) {
        try {
            if (StringUtils.isNotBlank(message)){
                internalTransferOrderBigdataService.execHistory(message);
            }
        } catch (Exception e) {
            log.info(e.toString());
            log.info("消息队列丢失消息:" + message);
        }
    }
}
